package com.glsc.ngateway.shortmsg.controller;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.api.shortmsg.utils.WorkWechatUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Objects;

/**
 * @author xuchang
 */
@RestController
@RequestMapping("/workwechat")
public class WorkWechatController {

    @RequestMapping(method = RequestMethod.POST, value = "sendMsg")
    public PlatformResponse<?> sendMsg(@RequestBody WorkWechatUtils.MessageGenericVo msg) throws IOException, InterruptedException {
        WorkWechatUtils.MessageResponse<Boolean> resp = WorkWechatUtils.sendMsg(msg);
        return (0 == resp.getCode() && Objects.nonNull(resp.getData()) && resp.getData()) ? PlatformResponse.success() : PlatformResponse.failed();
    }
}
